package ${classPath};

<#assign instance="${domain?substring(0,1)?lower_case}${domain?substring(1)}"/>
import java.util.ArrayList;
import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

/**
 * ${classComment}Controller
 * 
 * @author HU
 * @date 2023-10-10
 */
@RestController
@RequestMapping("/${artifact}/${domain}")
@Api(tags = {"${classComment}对象服务"})
public class ${domain}Controller extends BaseController {
  <#assign Vo="${domain}Vo" instance="${domain?substring(0,1)?lower_case}${domain?substring(1)}"/>
  @Autowired
  private ${domain}Service ${instance}Service;

  /**
   * 获取${classComment}详细信息
   */
  @GetMapping(path = "/{id}", produces = {"application/json"})
  @ApiOperation(value = "获取指定的${classComment}对象信息", notes = "根据 id 获取指定的${classComment}对象信息")
  @ApiResponses(value = { //
      @ApiResponse(code = 200, message = "请求成功", response = ${domain}Vo.class)//
  })
  public AjaxResult getInfo(@PathVariable("id") Long id) {
    ${domain} ${domain} = ${instance}Service.getById(id);
    return success(new ${Vo}(${domain}));
  }

  /**
   * 查询${classComment}列表
   */
  @GetMapping(path = "/list", produces = {"application/json"})
  @ApiOperation(value = "查询${classComment}对象信息", notes = "根据参数查询${classComment}对象信息，返回${classComment}对象分页列表")
  @ApiResponses(value = { //
      @ApiResponse(code = 200, message = "请求成功", response = ${Vo}.class)//
  })
  public TableDataInfo list(RyPage<${domain}> pageable, ${domain}QueryCommand command) {
    ${domain}Query query = command.convert();
    Page<${domain}> page = ${instance}Service.page(pageable, query.getQueryWrapper());
    return getDataTable(convert(page.getRecords()), page.getTotal());
  }

  /**
   * 新增${classComment}
   */
  @ApiOperation(value = "新增${classComment}对象信息", notes = "新增${classComment}对象信息",
      produces = "application/json")
  @PostMapping
  public AjaxResult add(@RequestBody ${domain}AddCommand command) {
    return toAjax(${instance}Service.save(command.convert()));
  }

  /**
   * 修改${classComment}
   */
  @ApiOperation(value = "修改${classComment}对象信息", notes = "修改${classComment}对象信息",
      produces = "application/json")
  @PutMapping
  public AjaxResult edit(@RequestBody ${domain}EditCommand command) {
    ${domain} ${domain} = ${instance}Service.getById(command.getId());
    command.fill(${domain});
    return toAjax(${instance}Service.updateById(${domain}));
  }

  /**
   * 删除${classComment}
   */
  @ApiOperation(value = "批量删除${classComment}对象信息", notes = "根据 id 批量删除${classComment}对象")
  @DeleteMapping("/{ids}")
  public AjaxResult remove(@PathVariable Long[] ids) {
    return toAjax(${instance}Service.removeByIds(Arrays.asList(ids)));
  }

  private List<${Vo}> convert(List<${domain}> list) {
    List<${Vo}> newList = new ArrayList<>();
    for (${domain} ${instance} : list) {
      newList.add(new ${Vo}(${instance}));
    }
    return newList;
  }
}
